package com.hanhanxiaochong.zhongxiangchuanmei.view.main.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.ShopListBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.CommonAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ViewHolder;
import com.hanhanxiaochong.zhongxiangchuanmei.util.ResourcesUtils;
import com.hanhanxiaochong.zhongxiangchuanmei.util.glide.GlideImgManager;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.util.List;

/**
 * Created by RockPhoenix on 2018/5/24.
 */

public class GoodListAdapter extends CommonAdapter<ShopListBean> {

    public GoodListAdapter(Context context, int layoutId, List<ShopListBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, ShopListBean bean, int position) {
        ImageView ivGoodPic = holder.getView(R.id.iv_good_pic);
        ImageView selfSupport = holder.getView(R.id.iv_self_support);
        TextView goodName = holder.getView(R.id.tv_good_name);
        TextView vipPrice = holder.getView(R.id.tv_vip_price);
        TextView normalPrice = holder.getView(R.id.tv_normal_price);
        ImageView becomVip = holder.getView(R.id.iv_becom_vip);
        GlideImgManager.glideLoader(mContext, RetrofitSource.image_url + (bean.getPic().split(",")[0]), R.mipmap.img_error, R.mipmap.img_error, ivGoodPic);
        selfSupport.setVisibility(bean.getSelf_support().equals("y") ? View.VISIBLE : View.GONE);
        goodName.setText(bean.getName());
        vipPrice.setText(String.format(ResourcesUtils.getString(R.string.vip_good_price), bean.getPrice_vip()));
        normalPrice.setText(String.format(ResourcesUtils.getString(R.string.normal_good_price), bean.getPrice()));
        holder.itemView.setOnClickListener(v -> mOnItemClickListener.onItemClick(this, position));
    }
}
